--
-- PostgreSQL database dump
--

-- Dumped from database version 9.0.0
-- Dumped by pg_dump version 9.0.0
-- Started on 2012-05-09 21:58:20

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 1898 (class 1262 OID 16393)
-- Dependencies: 1897
-- Name: stock; Type: COMMENT; Schema: -; Owner: stock
--

COMMENT ON DATABASE stock IS 'Esta es la Base de datos del Proyecto Stock de Eirete';


--
-- TOC entry 344 (class 2612 OID 11574)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

--
-- TOC entry 18 (class 1255 OID 16394)
-- Dependencies: 6 344
-- Name: producto_update_tr(); Type: FUNCTION; Schema: public; Owner: stock
--

CREATE FUNCTION producto_update_tr() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
  id_producto_au BIGINT;
  cantidad_anterior_au BIGINT;
  cantidad_posterior_au BIGINT;
  precio_anterior_au BIGINT;
  precio_posterior_au BIGINT;
BEGIN
	IF (TG_OP = 'UPDATE' ) THEN

		id_producto_au := OLD.id;
		cantidad_anterior_au := OLD.cantidad;
		cantidad_posterior_au := NEW.cantidad;
		precio_anterior_au := OLD.precio;
		precio_posterior_au := NEW.precio;  
        
        insert into auditoria_producto(id_producto,cantidad_anterior,cantidad_posterior,precio_anterior,precio_posterior,motivo)
		values (id_producto_au,cantidad_anterior_au,cantidad_posterior_au,precio_anterior_au,precio_posterior_au, 'ACTUALIZACION');         
		RETURN NULL;
            
	END IF;

END;

/*TG_OP puede ser INSERT, UPDATE OR DELETE*/
$$;


ALTER FUNCTION public.producto_update_tr() OWNER TO stock;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1536 (class 1259 OID 16395)
-- Dependencies: 6
-- Name: auditoria_cliente; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE auditoria_cliente (
    id bigint NOT NULL,
    id_cliente bigint NOT NULL,
    telefono_anterior character varying NOT NULL,
    telefono_posterior character varying NOT NULL,
    email_anterior character varying NOT NULL,
    email_posterior character varying NOT NULL
);


ALTER TABLE public.auditoria_cliente OWNER TO stock;

--
-- TOC entry 1901 (class 0 OID 0)
-- Dependencies: 1536
-- Name: TABLE auditoria_cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE auditoria_cliente IS 'Tabla que contiene todas las auditorias de los clientes.';


--
-- TOC entry 1537 (class 1259 OID 16401)
-- Dependencies: 6 1536
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE auditoria_cliente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.auditoria_cliente_id_seq OWNER TO stock;

--
-- TOC entry 1902 (class 0 OID 0)
-- Dependencies: 1537
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE auditoria_cliente_id_seq OWNED BY auditoria_cliente.id;


--
-- TOC entry 1903 (class 0 OID 0)
-- Dependencies: 1537
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('auditoria_cliente_id_seq', 1, false);


SET default_with_oids = true;

--
-- TOC entry 1538 (class 1259 OID 16403)
-- Dependencies: 6
-- Name: auditoria_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE auditoria_producto (
    id bigint NOT NULL,
    id_producto bigint NOT NULL,
    cantidad_anterior bigint NOT NULL,
    cantidad_posterior bigint NOT NULL,
    precio_anterior bigint NOT NULL,
    precio_posterior bigint NOT NULL,
    motivo character varying NOT NULL
);


ALTER TABLE public.auditoria_producto OWNER TO stock;

--
-- TOC entry 1904 (class 0 OID 0)
-- Dependencies: 1538
-- Name: TABLE auditoria_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE auditoria_producto IS 'Esta tabla es para la auditoria de producto.';


--
-- TOC entry 1905 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.id IS 'Identificador de la Auditoria Producto.';


--
-- TOC entry 1906 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.id_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.id_producto IS 'Identificador del Producto';


--
-- TOC entry 1907 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.cantidad_anterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.cantidad_anterior IS 'Cantidad Anterior';


--
-- TOC entry 1908 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.cantidad_posterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.cantidad_posterior IS 'Cantidad Posterior';


--
-- TOC entry 1909 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.precio_anterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.precio_anterior IS 'Precio Anterior';


--
-- TOC entry 1910 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.precio_posterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.precio_posterior IS 'Precio Posterior';


--
-- TOC entry 1911 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN auditoria_producto.motivo; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.motivo IS 'Motivo de Auditoria.';


--
-- TOC entry 1539 (class 1259 OID 16409)
-- Dependencies: 6 1538
-- Name: auditoria_producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE auditoria_producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.auditoria_producto_id_seq OWNER TO stock;

--
-- TOC entry 1912 (class 0 OID 0)
-- Dependencies: 1539
-- Name: auditoria_producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE auditoria_producto_id_seq OWNED BY auditoria_producto.id;


--
-- TOC entry 1913 (class 0 OID 0)
-- Dependencies: 1539
-- Name: auditoria_producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('auditoria_producto_id_seq', 5, true);


--
-- TOC entry 1540 (class 1259 OID 16411)
-- Dependencies: 6
-- Name: tipo_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE tipo_producto (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    descripcion character varying NOT NULL
);


ALTER TABLE public.tipo_producto OWNER TO stock;

--
-- TOC entry 1914 (class 0 OID 0)
-- Dependencies: 1540
-- Name: TABLE tipo_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE tipo_producto IS 'En esta tabla se tiene que administrar todas las categorias de Producto.';


--
-- TOC entry 1915 (class 0 OID 0)
-- Dependencies: 1540
-- Name: COLUMN tipo_producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.id IS 'Identificador de la Categoria.';


--
-- TOC entry 1916 (class 0 OID 0)
-- Dependencies: 1540
-- Name: COLUMN tipo_producto.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.nombre IS 'Nombre de la Categoría.';


--
-- TOC entry 1917 (class 0 OID 0)
-- Dependencies: 1540
-- Name: COLUMN tipo_producto.descripcion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.descripcion IS 'Descripción del Tipo de Producto.';


--
-- TOC entry 1541 (class 1259 OID 16417)
-- Dependencies: 6 1540
-- Name: categoria_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE categoria_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.categoria_id_seq OWNER TO stock;

--
-- TOC entry 1918 (class 0 OID 0)
-- Dependencies: 1541
-- Name: categoria_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE categoria_id_seq OWNED BY tipo_producto.id;


--
-- TOC entry 1919 (class 0 OID 0)
-- Dependencies: 1541
-- Name: categoria_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('categoria_id_seq', 17, true);


--
-- TOC entry 1542 (class 1259 OID 16419)
-- Dependencies: 6
-- Name: cliente; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE cliente (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    apellido character varying NOT NULL,
    telefono character varying NOT NULL,
    nro_doc character varying NOT NULL,
    direccion character varying NOT NULL,
    email character varying NOT NULL
);


ALTER TABLE public.cliente OWNER TO stock;

--
-- TOC entry 1920 (class 0 OID 0)
-- Dependencies: 1542
-- Name: TABLE cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE cliente IS 'En esta tabla se tiene que administrar todos los clientes del Sistema.';


--
-- TOC entry 1921 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.id IS 'Identificador del Cliente.';


--
-- TOC entry 1922 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.nombre IS 'Nombre del Cliente.';


--
-- TOC entry 1923 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.apellido; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.apellido IS 'Apellido del Cliente.';


--
-- TOC entry 1924 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.telefono; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.telefono IS 'Telefono del Cliente.';


--
-- TOC entry 1925 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.nro_doc; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.nro_doc IS 'Nro. Documento del cliente.';


--
-- TOC entry 1926 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.direccion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.direccion IS 'Direccion del Cliente.';


--
-- TOC entry 1927 (class 0 OID 0)
-- Dependencies: 1542
-- Name: COLUMN cliente.email; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.email IS 'Email del Cliente.';


--
-- TOC entry 1543 (class 1259 OID 16425)
-- Dependencies: 6 1542
-- Name: cliente_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE cliente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cliente_id_seq OWNER TO stock;

--
-- TOC entry 1928 (class 0 OID 0)
-- Dependencies: 1543
-- Name: cliente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE cliente_id_seq OWNED BY cliente.id;


--
-- TOC entry 1929 (class 0 OID 0)
-- Dependencies: 1543
-- Name: cliente_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('cliente_id_seq', 1, false);


--
-- TOC entry 1544 (class 1259 OID 16427)
-- Dependencies: 6
-- Name: compra; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE compra (
    id bigint NOT NULL,
    id_producto_comprado bigint NOT NULL,
    cantidad_comprada bigint NOT NULL,
    monto_compra bigint NOT NULL,
    id_usuario_catastrador bigint NOT NULL,
    fecha_compra timestamp without time zone NOT NULL
);


ALTER TABLE public.compra OWNER TO stock;

--
-- TOC entry 1930 (class 0 OID 0)
-- Dependencies: 1544
-- Name: TABLE compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE compra IS 'En esta tabla se tiene que administrar la compra de todos los productos que se realiza sobre el Sistema.';


--
-- TOC entry 1931 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id IS 'Identificador de la Compra.';


--
-- TOC entry 1932 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.id_producto_comprado; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id_producto_comprado IS 'Identificador del Producto Comprado.';


--
-- TOC entry 1933 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.cantidad_comprada; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.cantidad_comprada IS 'Cantidad de Compra.';


--
-- TOC entry 1934 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.monto_compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.monto_compra IS 'Monto de la Compra.';


--
-- TOC entry 1935 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.id_usuario_catastrador; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id_usuario_catastrador IS 'Identificador del Usuario Catastrador.';


--
-- TOC entry 1936 (class 0 OID 0)
-- Dependencies: 1544
-- Name: COLUMN compra.fecha_compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.fecha_compra IS 'Fecha de la Compra.';


--
-- TOC entry 1545 (class 1259 OID 16430)
-- Dependencies: 6 1544
-- Name: compra_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE compra_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.compra_id_seq OWNER TO stock;

--
-- TOC entry 1937 (class 0 OID 0)
-- Dependencies: 1545
-- Name: compra_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE compra_id_seq OWNED BY compra.id;


--
-- TOC entry 1938 (class 0 OID 0)
-- Dependencies: 1545
-- Name: compra_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('compra_id_seq', 1, false);


--
-- TOC entry 1546 (class 1259 OID 16432)
-- Dependencies: 6
-- Name: producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE producto (
    id bigint NOT NULL,
    codigo character varying NOT NULL,
    nombre character varying NOT NULL,
    id_tipo_producto bigint NOT NULL,
    cantidad bigint NOT NULL,
    precio bigint NOT NULL,
    id_proveedor bigint NOT NULL
);


ALTER TABLE public.producto OWNER TO stock;

--
-- TOC entry 1939 (class 0 OID 0)
-- Dependencies: 1546
-- Name: TABLE producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE producto IS 'En esta tabla se tiene que administrar todos los productos con podrán ser vendidos o comprados.';


--
-- TOC entry 1940 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.id IS 'Identificador del producto';


--
-- TOC entry 1941 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.codigo; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.codigo IS 'Código del Producto.';


--
-- TOC entry 1942 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.nombre IS 'Nombre del Producto.';


--
-- TOC entry 1943 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.id_tipo_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.id_tipo_producto IS 'Identificador del Tipo de Producto Asociado.';


--
-- TOC entry 1944 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.cantidad; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.cantidad IS 'Cantidad en Stock del Producto.';


--
-- TOC entry 1945 (class 0 OID 0)
-- Dependencies: 1546
-- Name: COLUMN producto.precio; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.precio IS 'Precio del Producto.';


--
-- TOC entry 1547 (class 1259 OID 16438)
-- Dependencies: 6 1546
-- Name: producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.producto_id_seq OWNER TO stock;

--
-- TOC entry 1946 (class 0 OID 0)
-- Dependencies: 1547
-- Name: producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE producto_id_seq OWNED BY producto.id;


--
-- TOC entry 1947 (class 0 OID 0)
-- Dependencies: 1547
-- Name: producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('producto_id_seq', 23, true);


--
-- TOC entry 1548 (class 1259 OID 16440)
-- Dependencies: 6
-- Name: proveedor; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE proveedor (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    nombre_responsable character varying NOT NULL,
    email_responsable character varying NOT NULL,
    telefono_responsable character varying NOT NULL
);


ALTER TABLE public.proveedor OWNER TO stock;

--
-- TOC entry 1948 (class 0 OID 0)
-- Dependencies: 1548
-- Name: TABLE proveedor; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE proveedor IS 'En esta tabla se tiene que administrar todos los proveedores que venden productos a la empresa.';


--
-- TOC entry 1949 (class 0 OID 0)
-- Dependencies: 1548
-- Name: COLUMN proveedor.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.id IS 'Identificador de los Proveedores.';


--
-- TOC entry 1950 (class 0 OID 0)
-- Dependencies: 1548
-- Name: COLUMN proveedor.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.nombre IS 'Nombre del Proveedor.';


--
-- TOC entry 1951 (class 0 OID 0)
-- Dependencies: 1548
-- Name: COLUMN proveedor.email_responsable; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.email_responsable IS 'Email del Responsable.';


--
-- TOC entry 1549 (class 1259 OID 16446)
-- Dependencies: 1548 6
-- Name: proveedor_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE proveedor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.proveedor_id_seq OWNER TO stock;

--
-- TOC entry 1952 (class 0 OID 0)
-- Dependencies: 1549
-- Name: proveedor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE proveedor_id_seq OWNED BY proveedor.id;


--
-- TOC entry 1953 (class 0 OID 0)
-- Dependencies: 1549
-- Name: proveedor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('proveedor_id_seq', 5, true);


--
-- TOC entry 1550 (class 1259 OID 16448)
-- Dependencies: 6
-- Name: rol; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE rol (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    descripcion character varying NOT NULL,
    hab_inh character varying(1) NOT NULL
);


ALTER TABLE public.rol OWNER TO stock;

--
-- TOC entry 1954 (class 0 OID 0)
-- Dependencies: 1550
-- Name: TABLE rol; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE rol IS 'En esta tabla se tiene que administrar todos los Roles del Sistema.';


--
-- TOC entry 1955 (class 0 OID 0)
-- Dependencies: 1550
-- Name: COLUMN rol.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.id IS 'Identificador del Rol.';


--
-- TOC entry 1956 (class 0 OID 0)
-- Dependencies: 1550
-- Name: COLUMN rol.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.nombre IS 'Nombre del Rol.';


--
-- TOC entry 1957 (class 0 OID 0)
-- Dependencies: 1550
-- Name: COLUMN rol.descripcion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.descripcion IS 'Funcion del Rol, actividades que realiza.';


--
-- TOC entry 1958 (class 0 OID 0)
-- Dependencies: 1550
-- Name: COLUMN rol.hab_inh; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.hab_inh IS 'Sus valores pueden ser:
* S= habilitado.
* N= deshabilitado.';


--
-- TOC entry 1551 (class 1259 OID 16454)
-- Dependencies: 1550 6
-- Name: rol_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE rol_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.rol_id_seq OWNER TO stock;

--
-- TOC entry 1959 (class 0 OID 0)
-- Dependencies: 1551
-- Name: rol_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE rol_id_seq OWNED BY rol.id;


--
-- TOC entry 1960 (class 0 OID 0)
-- Dependencies: 1551
-- Name: rol_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('rol_id_seq', 5, true);


--
-- TOC entry 1552 (class 1259 OID 16456)
-- Dependencies: 6
-- Name: usuario; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE usuario (
    id bigint NOT NULL,
    login_usuario character varying NOT NULL,
    contrasenha character varying NOT NULL,
    nombre character varying NOT NULL,
    telefono character varying NOT NULL,
    nro_doc character varying NOT NULL,
    estado_civil character varying(1) NOT NULL,
    direccion character varying NOT NULL,
    id_rol bigint NOT NULL,
    apellido character varying,
    hab_inh character varying(1)
);


ALTER TABLE public.usuario OWNER TO stock;

--
-- TOC entry 1961 (class 0 OID 0)
-- Dependencies: 1552
-- Name: TABLE usuario; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE usuario IS 'En esta tabla se tiene que administrar los usuarios del Sistema.';


--
-- TOC entry 1962 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.id IS 'Identificador del Usuario';


--
-- TOC entry 1963 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.login_usuario; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.login_usuario IS 'Login Name del Usuario, es uno de los parámetros de las credenciales de acceso.';


--
-- TOC entry 1964 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.contrasenha; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.contrasenha IS 'Contraseña del Usuario, es el otro parámetro para acceder al Sistema.';


--
-- TOC entry 1965 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.nombre IS 'Nombre del Usuario.';


--
-- TOC entry 1966 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.telefono; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.telefono IS 'Telefono del Usuario.';


--
-- TOC entry 1967 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.nro_doc; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.nro_doc IS 'Nro. de Documento del Usuario.';


--
-- TOC entry 1968 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.estado_civil; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.estado_civil IS 'Sus valores pueden ser:
* S=Soltero/a.
* C=Casado/a.
* V=Viudo/a.
* D=Divorciado/a.';


--
-- TOC entry 1969 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.direccion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.direccion IS 'Dirección del Usuario.';


--
-- TOC entry 1970 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.id_rol; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.id_rol IS 'Identificador del Rol Asociado.';


--
-- TOC entry 1971 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.apellido; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.apellido IS 'Apellido del Usuario.';


--
-- TOC entry 1972 (class 0 OID 0)
-- Dependencies: 1552
-- Name: COLUMN usuario.hab_inh; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.hab_inh IS 'Estado de Habilitación del Usuario.';


--
-- TOC entry 1553 (class 1259 OID 16462)
-- Dependencies: 6 1552
-- Name: usuario_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE usuario_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.usuario_id_seq OWNER TO stock;

--
-- TOC entry 1973 (class 0 OID 0)
-- Dependencies: 1553
-- Name: usuario_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE usuario_id_seq OWNED BY usuario.id;


--
-- TOC entry 1974 (class 0 OID 0)
-- Dependencies: 1553
-- Name: usuario_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('usuario_id_seq', 3, true);


--
-- TOC entry 1554 (class 1259 OID 16464)
-- Dependencies: 6
-- Name: venta; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE venta (
    id bigint NOT NULL,
    id_producto_venta bigint NOT NULL,
    cantidad_venta bigint NOT NULL,
    monto_venta bigint NOT NULL,
    iva_10 double precision NOT NULL,
    id_cliente bigint NOT NULL,
    fecha_venta timestamp without time zone NOT NULL,
    id_usuario_vendedor bigint NOT NULL
);


ALTER TABLE public.venta OWNER TO stock;

--
-- TOC entry 1975 (class 0 OID 0)
-- Dependencies: 1554
-- Name: TABLE venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE venta IS 'En esta tabla se tiene que administrar las cabeceras de todas las ventas.';


--
-- TOC entry 1976 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id IS 'Identificador de la Venta Cabecera.';


--
-- TOC entry 1977 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.id_producto_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_producto_venta IS 'Identificador del Producto Vendido.';


--
-- TOC entry 1978 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.cantidad_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.cantidad_venta IS 'Cantidad Vendida.';


--
-- TOC entry 1979 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.monto_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.monto_venta IS 'Precio Grupal de todos los detalles.';


--
-- TOC entry 1980 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.iva_10; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.iva_10 IS 'Iva 10%';


--
-- TOC entry 1981 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.id_cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_cliente IS 'Identificador del Cliente.';


--
-- TOC entry 1982 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.fecha_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.fecha_venta IS 'Fecha de la Venta.';


--
-- TOC entry 1983 (class 0 OID 0)
-- Dependencies: 1554
-- Name: COLUMN venta.id_usuario_vendedor; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_usuario_vendedor IS 'Identificador del Usuario Vendedor.';


--
-- TOC entry 1555 (class 1259 OID 16467)
-- Dependencies: 1554 6
-- Name: venta_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE venta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.venta_id_seq OWNER TO stock;

--
-- TOC entry 1984 (class 0 OID 0)
-- Dependencies: 1555
-- Name: venta_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE venta_id_seq OWNED BY venta.id;


--
-- TOC entry 1985 (class 0 OID 0)
-- Dependencies: 1555
-- Name: venta_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('venta_id_seq', 2, true);


--
-- TOC entry 1833 (class 2604 OID 16469)
-- Dependencies: 1539 1538
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE auditoria_producto ALTER COLUMN id SET DEFAULT nextval('auditoria_producto_id_seq'::regclass);


--
-- TOC entry 1835 (class 2604 OID 16470)
-- Dependencies: 1543 1542
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE cliente ALTER COLUMN id SET DEFAULT nextval('cliente_id_seq'::regclass);


--
-- TOC entry 1836 (class 2604 OID 16471)
-- Dependencies: 1545 1544
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE compra ALTER COLUMN id SET DEFAULT nextval('compra_id_seq'::regclass);


--
-- TOC entry 1837 (class 2604 OID 16472)
-- Dependencies: 1547 1546
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE producto ALTER COLUMN id SET DEFAULT nextval('producto_id_seq'::regclass);


--
-- TOC entry 1838 (class 2604 OID 16473)
-- Dependencies: 1549 1548
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE proveedor ALTER COLUMN id SET DEFAULT nextval('proveedor_id_seq'::regclass);


--
-- TOC entry 1839 (class 2604 OID 16474)
-- Dependencies: 1551 1550
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE rol ALTER COLUMN id SET DEFAULT nextval('rol_id_seq'::regclass);


--
-- TOC entry 1834 (class 2604 OID 16475)
-- Dependencies: 1541 1540
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE tipo_producto ALTER COLUMN id SET DEFAULT nextval('categoria_id_seq'::regclass);


--
-- TOC entry 1840 (class 2604 OID 16476)
-- Dependencies: 1553 1552
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE usuario ALTER COLUMN id SET DEFAULT nextval('usuario_id_seq'::regclass);


--
-- TOC entry 1841 (class 2604 OID 16477)
-- Dependencies: 1555 1554
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE venta ALTER COLUMN id SET DEFAULT nextval('venta_id_seq'::regclass);


--
-- TOC entry 1885 (class 0 OID 16395)
-- Dependencies: 1536
-- Data for Name: auditoria_cliente; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY auditoria_cliente (id, id_cliente, telefono_anterior, telefono_posterior, email_anterior, email_posterior) FROM stdin;
\.


--
-- TOC entry 1886 (class 0 OID 16403)
-- Dependencies: 1538
-- Data for Name: auditoria_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) FROM stdin;
1	23	15	20	10000	7500	0
2	23	15	15	10000	10000	ACTUALIZACION
3	23	15	23	10000	7500	ACTUALIZACION
4	23	15	23	10000	7500	ACTUALIZACION
5	23	15	23	10000	7500	ACTUALIZACION
\.


--
-- TOC entry 1888 (class 0 OID 16419)
-- Dependencies: 1542
-- Data for Name: cliente; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY cliente (id, nombre, apellido, telefono, nro_doc, direccion, email) FROM stdin;
1	Ana	Ruiz	o982345677	234567	Transchaco 435	abruiz@gmail.com
3	Ana	Ruiz	o982345677	789765	Transchaco 435	abruiz@gmail.com
2	Juan	Gonzalez	324213	3234567	calle sin nombre	juan@gmail.com
\.


--
-- TOC entry 1889 (class 0 OID 16427)
-- Dependencies: 1544
-- Data for Name: compra; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY compra (id, id_producto_comprado, cantidad_comprada, monto_compra, id_usuario_catastrador, fecha_compra) FROM stdin;
1	1	4	3450	2	2012-04-12 00:00:00
\.


--
-- TOC entry 1890 (class 0 OID 16432)
-- Dependencies: 1546
-- Data for Name: producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY producto (id, codigo, nombre, id_tipo_producto, cantidad, precio, id_proveedor) FROM stdin;
23	12346556	YOUGURT 300ML	17	23	7500	5
1	44	LECHE TREBOL	1	32	3300	1
\.


--
-- TOC entry 1891 (class 0 OID 16440)
-- Dependencies: 1548
-- Data for Name: proveedor; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY proveedor (id, nombre, nombre_responsable, email_responsable, telefono_responsable) FROM stdin;
5	TREBOL	RUBEN TROCHE	RUBENTROCHE@TREBOL.COM.PY	(0981)123123
1	 A.J Vierci	Antonio Vierci Jr.	ventas@ajvierci.com.py	021345654
\.


--
-- TOC entry 1892 (class 0 OID 16448)
-- Dependencies: 1550
-- Data for Name: rol; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY rol (id, nombre, descripcion, hab_inh) FROM stdin;
3	Vendedor	Administra las Ventas.	S
2	Catastrador	Administra Categorias, Productos, Cliente, Proveedor y Compra de Productos.	S
1	Administrador	Administra los Usuarios, Roles y Permisos del Sistema	S
\.


--
-- TOC entry 1887 (class 0 OID 16411)
-- Dependencies: 1540
-- Data for Name: tipo_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY tipo_producto (id, nombre, descripcion) FROM stdin;
17	Lacteos	Tipo de Producto Lacteos
1	LACTEOS	PRODUCTOS LACTEOS NACIONALES
\.


--
-- TOC entry 1893 (class 0 OID 16456)
-- Dependencies: 1552
-- Data for Name: usuario; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY usuario (id, login_usuario, contrasenha, nombre, telefono, nro_doc, estado_civil, direccion, id_rol, apellido, hab_inh) FROM stdin;
1	administrador	administrador	Marcelo	096547895	4776730	S	Luque km. 18	1	\N	\N
2	catastrador	catastrador	Sanie Benitez	0982707624	3879564	S	luque km.18	2	\N	\N
3	vendedor	vendedor	Ana Torres	096157787	3589456	S	Luque	3	\N	\N
\.


--
-- TOC entry 1894 (class 0 OID 16464)
-- Dependencies: 1554
-- Data for Name: venta; Type: TABLE DATA; Schema: public; Owner: stock
--

COPY venta (id, id_producto_venta, cantidad_venta, monto_venta, iva_10, id_cliente, fecha_venta, id_usuario_vendedor) FROM stdin;
3	23	2	5000	500	1	2014-06-05 00:00:00	3
5	23	8	4550	450	3	2014-06-05 00:00:00	3
\.


--
-- TOC entry 1845 (class 2606 OID 16493)
-- Dependencies: 1538 1538
-- Name: auditoria_producto_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT auditoria_producto_pkey PRIMARY KEY (id);


--
-- TOC entry 1847 (class 2606 OID 16495)
-- Dependencies: 1540 1540
-- Name: categoria_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT categoria_nombre_key UNIQUE (nombre);


--
-- TOC entry 1849 (class 2606 OID 16497)
-- Dependencies: 1540 1540
-- Name: categoria_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT categoria_pkey PRIMARY KEY (id);


--
-- TOC entry 1851 (class 2606 OID 16499)
-- Dependencies: 1542 1542
-- Name: cliente_nro_doc_cliente_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY cliente
    ADD CONSTRAINT cliente_nro_doc_cliente_key UNIQUE (nro_doc);


--
-- TOC entry 1853 (class 2606 OID 16501)
-- Dependencies: 1542 1542
-- Name: cliente_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY cliente
    ADD CONSTRAINT cliente_pkey PRIMARY KEY (id);


--
-- TOC entry 1855 (class 2606 OID 16503)
-- Dependencies: 1544 1544
-- Name: compra_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT compra_pkey PRIMARY KEY (id);


--
-- TOC entry 1843 (class 2606 OID 16505)
-- Dependencies: 1536 1536
-- Name: pk_auditoria_cliente; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY auditoria_cliente
    ADD CONSTRAINT pk_auditoria_cliente PRIMARY KEY (id);


--
-- TOC entry 1857 (class 2606 OID 16507)
-- Dependencies: 1546 1546
-- Name: producto_codigo_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT producto_codigo_key UNIQUE (codigo);


--
-- TOC entry 1859 (class 2606 OID 16509)
-- Dependencies: 1546 1546
-- Name: producto_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT producto_pkey PRIMARY KEY (id);


--
-- TOC entry 1861 (class 2606 OID 16511)
-- Dependencies: 1548 1548
-- Name: proveedor_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT proveedor_nombre_key UNIQUE (nombre);


--
-- TOC entry 1863 (class 2606 OID 16513)
-- Dependencies: 1548 1548
-- Name: proveedor_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT proveedor_pkey PRIMARY KEY (id);


--
-- TOC entry 1865 (class 2606 OID 16515)
-- Dependencies: 1550 1550
-- Name: rol_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY rol
    ADD CONSTRAINT rol_nombre_key UNIQUE (nombre);


--
-- TOC entry 1867 (class 2606 OID 16517)
-- Dependencies: 1550 1550
-- Name: rol_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY rol
    ADD CONSTRAINT rol_pkey PRIMARY KEY (id);


--
-- TOC entry 1869 (class 2606 OID 16519)
-- Dependencies: 1552 1552
-- Name: usuario_login_name_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_login_name_key UNIQUE (login_usuario);


--
-- TOC entry 1871 (class 2606 OID 16521)
-- Dependencies: 1552 1552
-- Name: usuario_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_pkey PRIMARY KEY (id);


--
-- TOC entry 1873 (class 2606 OID 16523)
-- Dependencies: 1554 1554
-- Name: venta_cabecera_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT venta_cabecera_pkey PRIMARY KEY (id);


--
-- TOC entry 1884 (class 2620 OID 16524)
-- Dependencies: 1546 18
-- Name: producto_update_tr; Type: TRIGGER; Schema: public; Owner: stock
--

CREATE TRIGGER producto_update_tr AFTER UPDATE ON producto FOR EACH ROW EXECUTE PROCEDURE producto_update_tr();


--
-- TOC entry 1874 (class 2606 OID 16525)
-- Dependencies: 1542 1852 1536
-- Name: fk_auditoria_cliente_cliente; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY auditoria_cliente
    ADD CONSTRAINT fk_auditoria_cliente_cliente FOREIGN KEY (id_cliente) REFERENCES cliente(id);


--
-- TOC entry 1875 (class 2606 OID 16530)
-- Dependencies: 1538 1546 1858
-- Name: fk_auditoria_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT fk_auditoria_producto FOREIGN KEY (id_producto) REFERENCES producto(id);


--
-- TOC entry 1876 (class 2606 OID 16535)
-- Dependencies: 1858 1544 1546
-- Name: fk_compra_producto_comprado; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT fk_compra_producto_comprado FOREIGN KEY (id_producto_comprado) REFERENCES producto(id);


--
-- TOC entry 1877 (class 2606 OID 16540)
-- Dependencies: 1870 1544 1552
-- Name: fk_compra_usuario_catastrador; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT fk_compra_usuario_catastrador FOREIGN KEY (id_usuario_catastrador) REFERENCES usuario(id);


--
-- TOC entry 1878 (class 2606 OID 16545)
-- Dependencies: 1548 1546 1862
-- Name: fk_producto_proveedor; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_proveedor FOREIGN KEY (id_proveedor) REFERENCES proveedor(id);


--
-- TOC entry 1879 (class 2606 OID 16550)
-- Dependencies: 1540 1848 1546
-- Name: fk_producto_tipo_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_tipo_producto FOREIGN KEY (id_tipo_producto) REFERENCES tipo_producto(id);


--
-- TOC entry 1880 (class 2606 OID 16555)
-- Dependencies: 1552 1866 1550
-- Name: fk_usuario_rol; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT fk_usuario_rol FOREIGN KEY (id_rol) REFERENCES rol(id);


--
-- TOC entry 1881 (class 2606 OID 16560)
-- Dependencies: 1554 1852 1542
-- Name: fk_venta_cliente; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_cliente FOREIGN KEY (id_cliente) REFERENCES cliente(id);


--
-- TOC entry 1882 (class 2606 OID 16565)
-- Dependencies: 1858 1554 1546
-- Name: fk_venta_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_producto FOREIGN KEY (id_producto_venta) REFERENCES producto(id);


--
-- TOC entry 1883 (class 2606 OID 16570)
-- Dependencies: 1554 1552 1870
-- Name: fk_venta_vendedor; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_vendedor FOREIGN KEY (id_usuario_vendedor) REFERENCES usuario(id);


--
-- TOC entry 1900 (class 0 OID 0)
-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-05-09 21:58:21

--
-- PostgreSQL database dump complete
--

